@extends('layouts.header')
@section('content')
<nav class="breadcrumb">
    <i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 检测业务 <span class="c-gray en">&gt;</span>
    <a href="javascript:;" onclick="location.href='/{{config('constant.name_admin')}}/contract/indexPrintBarCode';">打印条形码</a>
    <span class="c-gray en">&gt;</span> 点击进入【<span id="client_name">{{ $client_name }}</span>】
    <a class="btn btn-primary radius r" style="line-height:1.6em;margin-top:3px"
       href="javascript:location.replace(location.href);"
       title="刷新"><i class="Hui-iconfont">&#xe68f;</i></a>
    <a class="btn btn-primary radius r mr-10" style="line-height:1.6em;margin-top:3px"
       href="javascript:self.location=document.referrer;">
        <i class="Hui-iconfont Hui-iconfont-arrow1-left"></i>&nbsp;&nbsp;返回
    </a>
</nav>
<div class="hide">
    {{$enable_tool_ID = DB::table('setting')->where('id', '1')->value('enable_tool_ID')}}
</div>
<div class="page-container">
    <div class="cl pd-5 bg-1 bk-gray">
        <span class="l">
            <a class="btn btn-primary radius" href="javascript:;" onclick="toPrintBarCode(this,1)"><i class="Hui-iconfont Hui-iconfont-dayinji"></i> 批量打印条码</a>
            @if($enable_tool_ID)
                <a class="btn btn-primary radius" href="javascript:;" onclick="batch_print_RFID()"><i class="Hui-iconfont Hui-iconfont-dayinji"></i> 批量打印RFID</a>
                <!-- <a class="btn btn-primary radius" href="javascript:;" onclick="postKet_print_RFID()"><i class="Hui-iconfont Hui-iconfont-dayinji"></i> postKet</a> -->
                <!-- <a class="btn btn-primary radius" href="javascript:;" onclick="PTK_RFIDjz()"><i class="Hui-iconfont Hui-iconfont-dayinji"></i> RFID探测校准</a> -->
            @endif
        </span>
        <span class="r">
            <span class="mr-20" id="chosePrintRemote">
                <label><input type="radio" name="is_remote" value="1" @if(data_get($setting_info,'is_remote',0) == 1) checked @endif> 远程打印 </label>
                <label class="ml-10"><input type="radio" name="is_remote" value="0" @if(data_get($setting_info,'is_remote',0) == 0) checked @endif> 本地打印 </label>
            </span>
            <a class="btn btn-primary radius" href="javascript:;" onclick="passedcard_set()"><i class="Hui-iconfont Hui-iconfont-manage2"></i> 打印设置</a>
        </span>
    </div>
    <div class="tb_con">
        <div class="cl pd-5 bg-1 bk-gray" id="toolGroup"> </div>
        <div class="mt-10">
            <table class="table table-border table-bordered table-bg table-hover table-condensed table-responsive" id="datatable">
                <thead>
                    <tr class="text-c">
                        <th><input type="checkbox"></th>
                        <th>客户名称</th>
                        <th class="tool_name">工器具名称</th>
                        <th>类别</th>
                        <th>条形码</th>
                        <th>规格型号</th>
                        <th>分 类</th>
                        <th>额定电压</th>
                        <th>工器具ID</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                @foreach($data as $item)
                    @php 
                        $tool_name = $item->tool_name; 
                        array_set($toolCount,$tool_name,array_get($toolCount,$tool_name,0) + 1); 
                    @endphp
                    <tr class="text-c">
                        <td><input type="checkbox" value="{{$item->bar_code}}"></td>
                        <td class="client_name">{{$client_name}}</td>
                        <td class="tool_name">{{$item->tool_name}}</td>
                        <td class="class_name">{{$item->class_name}}</td>
                        <td class="bar_code">{{$item->bar_code}}</td>
                        <td class="guige_xinghao">{{$item->guige_xinghao}}</td>
                        <td class="class">{{$item->class}}</td>
                        <td class="voltage">{{$item->voltage}}</td>
                        <td class="gqj_ID">{{$item->gqj_ID}}</td>
                        <td>
                            <a class="btn btn-primary radius size-MINI" href="javascript:;" onclick="toPrintBarCode(this)">打印条码</a>
                            @if($enable_tool_ID)
                                <a class="ml-15 btn btn-primary radius size-MINI @if(!(strlen($item->gqj_ID) == 18 || strlen($item->gqj_ID) == 24) || strstr($item->gqj_ID,'?') > -1) disabled @endif"   onclick="print_RFID('{{$item->tool_name}}','{{$item->gqj_ID}}','{{$item->bar_code}}')">打印 RFID</a>
                            @endif
                        </td>
                    </tr>
                @endforeach
                </tbody>
            </table>
            <div class="f-r mt-10"><input class="input-text" type="text" value="" placeholder="指定页码" id="jumpPage"/></div>
        </div>
    </div>
</div>
<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="/admin/static/myfolder/js/printBarCode.js?ver={{config('constant.static_res_ver')}}"></script>
<script type="text/javascript" src="/admin/static/myfolder/js/printBarCodeContent_{{ $barCode_JS_file }}.js?ver={{config('constant.static_res_ver')}}"></script>
@if($enable_tool_ID)
    <script type="text/javascript" src="/admin/lib/POSTEK.js"></script>
    <script type="text/javascript" src="/admin/static/myfolder/js/printRFID{{$RFID_JS_file}}.js?ver={{config('constant.static_res_ver')}}"></script>
@endif
<script type="text/javascript">
    var client_name = $('#client_name').text();
    var print_depth = "{{ data_get($setting_info,'depth',12) }}";//合格证的打印深度
    var is_remote_print = {{ data_get($setting_info,'is_remote',0) }};//为本机打印或远程打印(本机打印:0 , 远程打印:1)
    var remote_ip = "{{ data_get($setting_info,'remote_ip','127.0.0.1') }}";//远程打印 ip
    var is_remote_RFID_print = {{ data_get($setting_info,'is_remote_RFID','false') }};//为本机打印或远程打印(本机打印:0 , 远程打印:1)--RFID
    var remote_ip_RFID = is_remote_RFID_print ? "{{ data_get($setting_info,'remote_ip_RFID','') }}" : "127.0.0.1";//远程打印 ip--RFID
    var RFIDurl = "http://"+remote_ip_RFID+":888/postek/print";
    // var RFIDurl = "http://127.0.0.1:888/postek/print";
    var DataName="";
    var PTKprinterUsbPort=255;

    @if(isAdmin())
        is_remote_RFID_print = 0;
        remote_ip_RFID = '127.0.0.1';
        var isadmin = true;
    @endif
    var table;
    $(function () {
        // $.fn.dataTable.ext.errMode = 'throw';//datatable抛异常的方式，在console中输出，默认以alert的方式弹出
        table = $('#datatable').DataTable({
            ordering: false, // 是否排序
            pageLength: 10,
            serverSide: false,//服务器端处理模式——此模式下如：过滤、分页、排序的处理都放在服务器端进行。
            language: { url: '/admin/lib/datatables/dataTables_Chinese_Lang.json' },
        });
        @if($enable_tool_ID) getPTKPrinterList(); @endif
        
        var toolCount = @json($toolCount);
        for(let tool_name in toolCount){
            $('#toolGroup').append('<span class="ml-10 " onclick="searchTool(this)"><span class="tool-name">'+tool_name+'</span>('+toolCount[tool_name]+')</span>');
        }
    });

    function searchTool(obj) {
        $(obj).css('color', '#5a98de')
        $(obj).siblings().css('color', '#000')
        let toolname = $(obj).find('.tool-name').text(),
            index = $(obj).closest('div.tb_con').find('thead th.tool_name').index();
        // console.log(index);
        $('input[type=search]').val(toolname);
        table.column(index).search('^' + toolname + '$', true, false).draw();
    }

    /*表格重新加载*/
    function table_reload(bool) {
        //清除表头 CheckBox的对勾
        $("#datatable").find("thead").find("input[type=checkbox]").removeAttr('checked');
        if (bool) {
            //true时，跳到第一页
            table.ajax.reload();
        } else {
            //false时，停留在原来页
            table.ajax.reload(null, false);
        }
    }

    /*删除*/
    function del(id) {
        var index2;
        layer.confirm('确认要删除吗？', function (index) {
            $.ajax({
                type: 'GET',
                url: '/{{config('constant.name_admin')}}/client/del' + '?id=' + id,
                // dataType: 'json',
                success: function (data) {
                    // console.log(data);
                    if (data === '1') {
                        table_reload(0);//0停留在当前页，1回到第一页
                        layer.msg('删除成功!', {icon: 1, time: 2000});
                    } else {
                        layer.msg('删除失败!', {icon: 2, time: 2000});
                    }
                },
                error: function (data) {
                    ajax_error(data);
                },
                beforeSend: function () {
                    //0.4透明度 白色遮罩
                    index2 = layer.load(2, {shade: [0.05, '#000']});
                },
                complete: function () {
                    layer.close(index2);
                },
            });
        });
    }

    /*编辑*/
    function edit(title, url, id, w, h) {
        layer_show(title, url + '?id=' + id, w, h);
    }

    /*添加*/
    function add(title, url, w, h) {
        layer_show(title, url, w, h);
    }

    /* 条形码设置 */
    function passedcard_set() {
        var title = '标签设置';
        var url = '/{{config('constant.name_admin')}}/setting/printBarCodeSet';
        var w = 800;
        var h = 500;
        layer_show(title, url, w, h);
    }

    /*打印条形码*/
    function toPrintBarCode(obj,isBatch=0){
        if (isBatch == 1) { //如果是批量打印
            batch_print();
        }else{
            print_barcode(obj);
        }
    }
    $('input[name=is_remote]','#chosePrintRemote').on('change',function () {
        is_remote_print = parseInt($(this).val());
        connection(); //连接打印机
    })
</script>
@endsection